function andPerceptron = andPerceptron(b,e,N, metodo)

w = rand(N+1,1)-0.5; 

psi=generarPatrones(N);
s=generarSoluciones(psi, N);
%if(metodo~=3)
	psi=escalar(psi);
	s=escalar(s);
	psi = agregarUmbral(psi,N, -1)
%else
%	psi = agregarUmbral(psi,N, 0)
%endif

s

j=0;
aciertos=0;
do
  indices = randperm(2^N);
  error=0;
  for ind=1:2^N
    i=indices(ind);
	
	%no lineal tanh
	if (metodo==0)
		o = tanh(b*psi(i,:)*w);		
		delta = (s(i)-o)*b*(1-o^2);	
		error += (s(i)-o)^2;
	endif
	
	%escalon
	if (metodo==1)
		o = sign(psi(i,:)*w);			
		delta=(s(i)-o);					
		
		if (s(i)==o) 
			aciertos+=1;
		else
			aciertos=0;
		endif
	endif
	
	% lineal
	if (metodo==2)
		o = psi(i,:)*w;		
		delta = (s(i)-o);	
		error += (s(i)-o)^2;
	endif
	
	%no lineal exp
	if (metodo==3)
		o = 1/(1 + exp(-2*b*psi(i,:)*w));
		delta = (s(i)-o)*2*b*o*(1-o);	
		error += (s(i)-o)^2;
	endif
	
	dW = e*delta*psi(i,:);
	w=w.+dW';
  endfor
  
  error *= 1/2;
  error
  
  j++;
until(j==30000 || error<10e-3);
%until(j==30000 || aciertos>1000);

for i=1:2^N
	o=tanh(b*psi(i,:)*w)
endfor
aciertos
j
error
w

endfunction